<?php

class SystemController extends AdminController
{

    public function actionSetting()
    {
        Yii::app()->session['nav_selected'] = Yii::app()->request->getQuery('index', 0);
        if (!Yii::app()->request->isPostRequest) {
            $data['rush_time_arr'] = Config::model()->get('rush_time_arr');//高峰时间
            if (!is_array($data['rush_time_arr'])) {
                $data['rush_time_arr'] = CJSON::decode($data['rush_time_arr']);
            }
            $data['expre_goods_id'] = Config::model()->get('expre_goods_id');//快递到手商品

            $data['mi_push_package_name_xhup_android'] = Config::model()->get('mi_push_package_name_xhup_android');//小米推送包名安卓 跑男端
            $data['mi_push_secret_xhup_android'] = Config::model()->get('mi_push_secret_xhup_android');//小米推送秘钥安卓 跑男端
            $data['mi_push_package_name_xhu_android'] = Config::model()->get('mi_push_package_name_xhu_android');//小米推送包名安卓 用户端
            $data['mi_push_secret_xhu_android'] = Config::model()->get('mi_push_secret_xhu_android');//小米推送包名安卓 用户端

            $data['mi_push_package_name_xhup_ios'] = Config::model()->get('mi_push_package_name_xhup_ios');//小米推送包名IOS 跑男端
            $data['mi_push_secret_xhup_ios'] = Config::model()->get('mi_push_secret_xhup_ios');//小米推送包名IOS 跑男端

            $data['mi_push_package_name_xhu_ios'] = Config::model()->get('mi_push_package_name_xhu_ios');//小米推送包名IOS 用户端
            $data['mi_push_secret_xhu_ios'] = Config::model()->get('mi_push_secret_xhu_ios');//小米推送包名IOS 用户端

            $data['service_mobile'] = Config::model()->get('service_mobile');//客服电话 
            $data['web_host'] = Config::model()->get('web_host');//网站地址 
            $data['check_index_text'] = Config::model()->get('check_index_text');//首页title 
            $data['receive_scope'] = Config::model()->get('receive_scope');//附近跑男  
            $data['alidayu_appkey'] = Config::model()->get('alidayu_appkey');//阿里大于 
            $data['alidayu_secret'] = Config::model()->get('alidayu_secret');//阿里大于
            $data['max_message_push_times'] = Config::model()->get('max_message_push_times');//推送最大次数 
            $data['max_message_push_count'] = Config::model()->get('max_message_push_count');//推送最大次数 
            $data['is_must'] = Config::model()->get('is_must');//是否必须升级 
            $data['js_config'] = Config::model()->get('js_config');//CNZZ 
            $data['logo'] = Config::model()->get('logo');//logo 
            $data['icp'] = Config::model()->get('icp');//icp  

            $data['signed_integral'] = Config::model()->get('signed_integral');//签到赠送积分 
            $data['login_integral'] = Config::model()->get('login_integral');//登录赠送积分
            $data['gorder_integral'] = Config::model()->get('gorder_integral');//发布货源赠送积分
            $data['tender_integral'] = Config::model()->get('tender_integral');//确认承运人赠送积分 
            $data['sign_integral'] = Config::model()->get('sign_integral');//收货赠送积分

            $data['web_keyword'] = Config::model()->get('web_keyword');//web_keyword
            $data['web_desc'] = Config::model()->get('web_desc');//web_desc 

            if (empty($data['longitude']) || empty($data['latitude']) || $data['longitude'] <= 0 || $data['latitude'] <= 0) {
                $data['longitude'] = 104.0;
                $data['latitude'] = 30.663;
            }
            $this->setPageTitle('系统设置');
            $name = Yii::app()->session->get('adminName');
            if ($name == 'admin' || true) {
                $this->render('setting', $data);
            } else {
                $this->redirect($this->createUrl('default/index'));
            }
        } else {
            Config::model()->set('mi_push_package_name_xhup_android', $_POST['mi_push_package_name_xhup_android']);//小米推送包名安卓 跑男端
            Config::model()->set('mi_push_secret_xhup_android', $_POST['mi_push_secret_xhup_android']);//小米推送秘钥安卓 跑男端
            Config::model()->set('mi_push_package_name_xhu_android', $_POST['mi_push_package_name_xhu_android']);//小米推送包名安卓 用户端
            Config::model()->set('mi_push_secret_xhu_android', $_POST['mi_push_secret_xhu_android']);//小米推送包名安卓 用户端
            Config::model()->set('mi_push_package_name_xhup_ios', $_POST['mi_push_package_name_xhup_ios']);//小米推送包名IOS 跑男端
            Config::model()->set('mi_push_secret_xhup_ios', $_POST['mi_push_secret_xhup_ios']);//小米推送包名IOS 跑男端
            Config::model()->set('mi_push_package_name_xhu_ios', $_POST['mi_push_package_name_xhu_ios']);//小米推送包名IOS 用户端
            Config::model()->set('mi_push_secret_xhu_ios', $_POST['mi_push_secret_xhu_ios']);//小米推送包名IOS 用户端

            Config::model()->set('web_keyword', $_POST['web_keyword']);//在线聊天key
            Config::model()->set('web_desc', $_POST['web_desc']);//在线聊天key
            Config::model()->set('web_host', $_POST['web_host']);//网站地址
            Config::model()->set('check_index_text', $_POST['check_index_text']);//首页title
            Config::model()->set('alidayu_appkey', $_POST['alidayu_appkey']);//阿里大于
            Config::model()->set('alidayu_secret', $_POST['alidayu_secret']);//阿里大于
            Config::model()->set('max_message_push_times', $_POST['max_message_push_times']);//推送最大次数/时间
            Config::model()->set('max_message_push_count', $_POST['max_message_push_count']);//推送最大次数/时间
            Config::model()->set('is_must', $_POST['is_must']);//是否必须升级
            Config::model()->set('js_config', $_POST['js_config']);//CNZZ code
            Config::model()->set('logo', $_POST['logo']);//logo
            Config::model()->set('icp', $_POST['icp']);//icp

            Config::model()->set('signed_integral', $_POST['signed_integral']);//签到赠送积分
            Config::model()->set('login_integral', $_POST['login_integral']);//登录赠送积分
            Config::model()->set('gorder_integral', $_POST['gorder_integral']);//发布货源赠送积分
            Config::model()->set('tender_integral', $_POST['tender_integral']);//确认承运人赠送积分
            Config::model()->set('sign_integral', $_POST['sign_integral']);//收货赠送积分

            $this->showSuccess('修改成功', $this->createUrl('system/setting'));
        }
    }

    //支付相关
    public function actionPayinfo()
    {
        $this->setPageTitle('支付相关配置');
        if (Yii::app()->request->isPostRequest) {
            Config::model()->set('merchant_no', $_POST['merchant_no']);//->平安银行 支付账号
            Config::model()->set('merchant_cert_path', $_POST['merchant_cert_path']);//->平安银行 支付证书
            Config::model()->set('merchant_cert_pass', $_POST['merchant_cert_pass']);//->平安银行 支付密码
            Config::model()->set('pingan_cert_public_key', $_POST['pingan_cert_public_key']);//->平安银行 支付key
            $this->showSuccess('修改成功', $this->createUrl('system/payinfo'));
        }
        $data['merchant_no'] = Config::model()->get('merchant_no');//平安银行 支付账号
        $data['merchant_cert_path'] = Config::model()->get('merchant_cert_path');//平安银行 支付证书
        $data['merchant_cert_pass'] = Config::model()->get('merchant_cert_pass');//平安银行 支付密码
        $data['pingan_cert_public_key'] = Config::model()->get('pingan_cert_public_key');//平安银行 支付key
        $this->render('payinfo', $data);
    }

    public function actionParam()
    {
        $this->setPageTitle('参数配置');
        Yii::app()->session['nav_selected'] = Yii::app()->request->getQuery('index', 0);
        if (!Yii::app()->request->isPostRequest) {
            $data['site_index'] = Config::model()->get('site_index');//首页  
            $name = Yii::app()->session->get('adminName');
            if ($name == 'admin' || true) {
                $this->render('param', $data);
            } else {
                $this->redirect($this->createUrl('default/index'));
            }
        } else {
            Config::model()->set('site_index', Yii::app()->request->getPost('site_index'));//首页
            $this->showSuccess('修改成功', $this->createUrl('system/param'));
        }
    }

    public function actionCommand()
    {
        if (Yii::app()->request->isPostRequest) {
            $key = Yii::app()->request->getPost('key');
            Yii::app()->cache->delete($key);
        }
        $this->render('command');
    }

    public function actionArticle()
    {
        $this->setPageTitle('文章配置');
        if (!Yii::app()->request->isPostRequest) {
            $data['userregister'] = Config::model()->get('userregister');//注册  
            $data['gorder'] = Config::model()->get('gorder');//货源发布 
            $data['authentication'] = Config::model()->get('authentication');//车主认证  
            $data['intro'] = Config::model()->get('intro');//公司介绍  

            $data['express_info'] = Config::model()->get('express_info');//运输管理  
            $data['joint_work'] = Config::model()->get('joint_work');//合作伙伴协议  
            $data['driver_info'] = Config::model()->get('driver_info');//合作伙伴协议  
            $data['type'] = Yii::app()->request->getQuery('type');
            $name = Yii::app()->session->get('adminName');
            if ($name == 'admin' || true) {
                $this->render('article', $data);
            } else {
                $this->redirect($this->createUrl('default/index'));
            }
        } else {
            $type = Yii::app()->request->getPost('type');
            if ($type != 'tms') {
                Config::model()->set('userregister', Yii::app()->request->getPost('userregister'));//注册
                Config::model()->set('gorder', Yii::app()->request->getPost('gorder'));//注册
                Config::model()->set('authentication', Yii::app()->request->getPost('authentication'));//注册
                Config::model()->set('intro', Yii::app()->request->getPost('intro'));//注册
            } else {
                Config::model()->set('express_info', Yii::app()->request->getPost('express_info'));//注册
                Config::model()->set('joint_work', Yii::app()->request->getPost('joint_work'));//注册
                Config::model()->set('driver_info', Yii::app()->request->getPost('driver_info'));//注册
            }
            $this->showSuccess('修改成功', $this->createUrl('system/article?type=' . $type));
        }
    }

    public function actionUpload()
    {
        $this->setPageTitle('心跳包配置');
        if (!Yii::app()->request->isPostRequest) {
            $data['location_upload_time'] = Config::model()->get('location_upload_time');//注册  
            $name = Yii::app()->session->get('adminName');
            if ($name == 'admin' || true) {
                $this->render('upload', $data);
            } else {
                $this->redirect($this->createUrl('default/index'));
            }
        } else {
            Config::model()->set('location_upload_time', Yii::app()->request->getPost('location_upload_time'));//注册
            $this->showSuccess('修改成功', $this->createUrl('system/upload'));
        }
    }


}